package com.ray.auth.common.log;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.ray.auth.system.table.entity.Logs;
import com.ray.auth.system.table.mapper.LogsMapper;
import com.xiaoleilu.hutool.util.ObjectUtil;
import com.zjhc.flyhong.common.function.enums.DeleteEnum;
import com.zjhc.flyhong.common.function.operator.LoginUser;
import com.zjhc.flyhong.common.handler.SystemLog;
import com.zjhc.flyhong.common.util.UUIDUtil;
import com.zjhc.flyhong.common.web.base.BaseService;
/**
 * 系统日志
 * @author ray
 *
 */
public class SystemLogService extends BaseService implements SystemLog{
	private static Logger logger = Logger.getLogger(SystemLogService.class);

	@Autowired
	private LogsMapper logsMapper;

	@Transactional
	public void saveLog(LoginUser loginUser, String mothed, String mothedParams) {
		try {
			if(ObjectUtil.isNotNull(loginUser)){
				Logs entity = new Logs();
				entity.setTenantId(loginUser.getTenantId());
				entity.setId(UUIDUtil.getUUID());
				entity.setIsDelete(DeleteEnum.USE.getValue());
				entity.setLoginName(loginUser.getLoginName());
				entity.setOperatorTime(new Date());
				entity.setOperatorContent(mothedParams);
				entity.setOperatorUser(loginUser.getUserName());
				entity.setUserId(loginUser.getUserId());
				entity.setOperatorType(mothed);
				this.setUserForAdd(entity, loginUser);
				logsMapper.insert(entity);
			}
		} catch (Exception e) {
			logger.error("logs insert error");
		}
		
		
	}
	
}
